//
//  EFSpecialOfferCell.m
//  EnjogFood
//
//  Created by 王芳 on 17/5/2.
//  Copyright © 2017年 wf. All rights reserved.
//

#import "EFSpecialOfferCell.h"
#import "EFSepecialItem.h"
#import "EFSaleView.h"

@interface EFSpecialOfferCell ()
@property (strong, nonatomic) UILabel *sepcialLabel;
@property (strong, nonatomic) UIScrollView *contentScrollView;
@property (strong, nonatomic) NSMutableArray *saleViews;
@property (strong, nonatomic) NSMutableArray *saleItems;
@end

@implementation EFSpecialOfferCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initUI];
        self.backgroundColor = RGBCOLOR(0xf5f9f9);
    }
    return self;
}

- (void)initUI{
    [self.contentView addSubview:self.sepcialLabel];
    [self.contentView addSubview:self.contentScrollView];
    self.contentScrollView.top = self.sepcialLabel.bottom + 8;
}

- (void)setObject:(NSArray *)items{
    CGFloat x = 20;
    CGFloat y = 0;
    for (EFSepecialItem *item in items) {
        EFSaleView *view = [[EFSaleView alloc] initWithFrame:CGRectMake(x, y, 102, 170) Item:item];
        
        x += 102 + 5;
        [self.contentScrollView addSubview:view];
    }
    self.contentScrollView.contentSize = CGSizeMake(20 + items.count * 102 + (items.count - 1)*5, 170);
}

- (UILabel *)sepcialLabel{
    if (!_sepcialLabel) {
        _sepcialLabel = [[UILabel alloc] init];
        _sepcialLabel.font = [UIFont systemFontOfSize:13];
        _sepcialLabel.textColor = RGBCOLOR(0xc0b565);
        _sepcialLabel.text = @"限时优惠";
        [_sepcialLabel sizeToFit];
        _sepcialLabel.top = 18;
        _sepcialLabel.left = 20;
    }
    return _sepcialLabel;
}

- (UIScrollView *)contentScrollView{
    if (!_contentScrollView) {
        _contentScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 170)];
        _contentScrollView.showsHorizontalScrollIndicator = false;
    }
    return _contentScrollView;
}

@end
